From 41730cbfb9289b38c6808bc14bfdbb7e304b3a21 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 30 Apr 2014 00:50:16 -0700 Subject: [PATCH] Fixed "getCachedWork" callback in thumb.php to avoid 404s in the stream method Change-Id: Id3781b87023291b9f7b2c7b3d8ae429a4065c227 --- thumb.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/thumb.php b/thumb.php index c5da918e08..a5a2bcc12f 100644 --- a/thumb.php +++ b/thumb.php @@ -327,7 +327,7 @@ function wfStreamThumb( array $params ) { } // Actually generate a new thumbnail - list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName ); + list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); // Check for thumbnail generation errors... $msg = wfMessage( 'thumbnail_error' ); @@ -356,9 +356,10 @@ function wfStreamThumb( array $params ) { * @param File $file * @param array $params * @param string $thumbName + * @param string $thumbPath * @return array (MediaTransformOutput|bool, string|bool error message HTML) */ -function wfGenerateThumbnail( File $file, array $params, $thumbName ) { +function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath ) { global $wgMemc, $wgAttemptFailureEpoch; $key = wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch, @@ -389,8 +390,12 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName ) { 'doWork' => function() use ( $file, $params ) { return $file->transform( $params, File::RENDER_NOW ); }, - 'getCachedWork' => function() use ( $file, $params ) { - return $file->transform( $params ); + 'getCachedWork' => function() use ( $file, $params, $thumbPath ) { + // If the worker that finished made this thumbnail then use it. + // Otherwise, it probably made a different thumbnail for this file. + return $file->getRepo()->fileExists( $thumbPath ) + ? $file->transform( $params ) + : false; // retry once more in exclusive mode }, 'fallback' => function() { return wfMessage( 'generic-pool-error' )->parse(); -- 2.20.1